FUNCTION calcSelectivities
  {
	/*
		This function loops over each ngear and calculates the corresponding
		selectivity for that gear type. It first uses a switch statement 
		to calculate selectivity curves based on isel_type where:
		1) logistic selectivity with 2 parameters
		2) Fixed logistic
	*/
	int k,i,j;
	dvariable p1,p2;
	sel_fish.initialize();
	sel_reclas.initialize();
	sel_pelaces.initialize();
	
	for(k=1;k<=3;k++) //antes ngear
	{
		switch(isel_type(j))
		{
			case 1:
				// logistic selectivity for case 1 or 2
				p1 = mfexp(sel_par(j,1,1));
				p2 = mfexp(sel_par(j,1,2));
				//jlog_sel(j) = log( plogis(age,p1,p2)+tiny );
				if(k==1){
					for(i=1;i<=nco;i++)
					{
						rec=mes_rec(i);
						surv=mes_surv(i);
						for(j=rec;j<=surv;j++)
						{
							sel_fish(j,i)=1./(1.+mfexp((p1-s_ageco(j,i))/p2));
						}
					}
				}

				if(k==2){
					for(i=1;i<=nco;i++)
					{
						rec=mes_rec(i);
						surv=mes_surv(i);
						for(j=rec;j<=surv;j++)
						{
							sel_reclas(j,i)=1./(1.+mfexp((p1-s_ageco(j,i))/p2));
						}
					}
				}
				if(k==3){
					for(i=1;i<=nco;i++)
					{
						rec=mes_rec(i);
						surv=mes_surv(i);
						for(j=rec;j<=surv;j++)
						{
							sel_pelaces(j,i)=1./(1.+mfexp((p1-s_ageco(j,i))/p2));
						}
					}
				}

				break;
			
			case 2:
				p1 = mfexp(sel_par(j,1,1));
				p2 = mfexp(sel_par(j,1,2));
				if(k==1){
					for(i=1;i<=nco;i++)
					{
						rec=mes_rec(i);
						surv=mes_surv(i);
						for(j=rec;j<=surv;j++)
						{
							sel_fish(j,i)=1./(1.+mfexp((p1-s_ageco(j,i))/p2));
						}
					}
				}

				if(k==2){
					for(i=1;i<=nco;i++)
					{
						rec=mes_rec(i);
						surv=mes_surv(i);
						for(j=rec;j<=surv;j++)
						{
							sel_reclas(j,i)=1./(1.+mfexp((p1-s_ageco(j,i))/p2));
						}
					}
				}
				if(k==3){
					for(i=1;i<=nco;i++)
					{
						rec=mes_rec(i);
						surv=mes_surv(i);
						for(j=rec;j<=surv;j++)
						{
							sel_pelaces(j,i)=1./(1.+mfexp((p1-s_ageco(j,i))/p2));
						}
					}
				}

				break;
				
			case 3:
				// age-specific selectivity coefficients
				//jlog_sel(j)(sage,nage-1) = sel_par(j)(sage);
				//jlog_sel(j,nage) = jlog_sel(j,nage-1);
				break;
				
			//default:
				//jlog_sel(j)=0;
				//break;
				
		}  // switch
	
	}
	
	if(verbose)cout<<"**** Ok after calcSelectivities ****"<<endl;
	
  }
